<?php

class QnewsController extends Controller {

    public $layout = "application.views.layouts.admin";

    public function filters() {
        return array(
            'accessControl',
        );
    }

    public function accessRules() {
        return array(
            array('allow',
                'actions' => array('List', 'Del', 'Add', 'Update'),
                'roles' => array('admin')
            ),
            array('deny',
                'actions' => array('List', 'Del', 'Add', 'Update'),
                'roles' => array('guest', 'user')
            )
        );
    }

    public function actionList() {
        $news = News::model()->findAll();
        $this->render('application.views.qnews.list', array("news" => $news));
    }

    public function actionAdd() {
        if ((isset($_POST['title'])) && (isset($_POST['redactor_content']))) {
            $news = new News();
            $news->title = $_POST['title'];
            $news->content = $_POST['redactor_content'];
            $news->create_time = date('Y-m-d');

            if ($news->save()) {
                $this->redirect(array('list'));
            } else {
                $this->redirect('error');
            }
        }
        $this->render('application.views.qnews.add');
    }

}

?>